package com.chuangke.mds.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.chuangke.mds.service.MdsSimulateReportQuarterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.chuangke.common.db.page.CkPageQuery;
import com.chuangke.common.http.HttpResult;
import com.chuangke.mds.entity.TechnologyProcess;
import com.chuangke.mds.service.TechnologyProcessService;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("zchkcl/technologyProcess")
public class TechnologyProcessController {

	@Autowired
	private TechnologyProcessService technologyProcessService;
	@Autowired
	private MdsSimulateReportQuarterService mdsSimulateReportQuarterService;
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping("/upload")
	public HttpResult upload(MultipartFile file) {
		return HttpResult.ok(technologyProcessService.upload(file));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/save")
	public HttpResult save(@RequestBody TechnologyProcess record) {
		return HttpResult.ok(technologyProcessService.saveOrUpdate(record));
	}
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping("/returnFile")
	public HttpResult returnFile(@RequestBody Map<String ,Object> params  ) throws IOException {
		return HttpResult.ok(technologyProcessService.returnFile(params));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/delete")
	public HttpResult delete(@RequestBody List<String> billIds) {
		technologyProcessService.delete(billIds);
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping("/page")
	public HttpResult page(@RequestBody Map<String, Object> params) {
		return HttpResult.ok(technologyProcessService.page(new CkPageQuery(params)));
	}
	

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping("/load")
	public HttpResult load(@RequestParam String id) {
		return HttpResult.ok(technologyProcessService.load(id));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping("/taskSimulation")
	public HttpResult taskSimulation(@RequestParam String id) {
		return HttpResult.ok(technologyProcessService.taskSimulation(id));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping("/update2SaveSimulate")
	public HttpResult update2SaveSimulate(@RequestBody Map<String, Object> params) {
		technologyProcessService.update2SaveSimulate(params);
		return HttpResult.ok();
	}

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping("/exportTechnology")
	public void exportTechnology(@RequestParam String id, HttpServletResponse response) throws IOException {
		mdsSimulateReportQuarterService.exportTechnology(id,response);
	}
	
}
